Skip to content

feat: session archive, sub-agent inspection UI, and live sub-agent streaming#4

Draft
rblalock wants to merge 3 commits intomainfrom
feature/sqlite-session-archive-subagent-ui
Draft

feat: session archive, sub-agent inspection UI, and live sub-agent streaming#4
rblalock wants to merge 3 commits intomainfrom
feature/sqlite-session-archive-subagent-ui

Conversation

@rblalock
Copy link
Member

@rblalock rblalock commented Feb 14, 2026

Summary

  • Session Archive: Stores conversation data in PostgreSQL. Terminated sessions show archived conversations in read-only mode with an "Archived" banner and Fork button.
  • Sub-Agent Inspection: Tool calls for task and agentuity_background_task now show an "Inspect Agent Session" button that expands to reveal the child agent's full conversation inline.
  • Live Sub-Agent Streaming: SSE proxy forwards child session events in real-time. Expanded child sessions show live streaming with an animated "Live" indicator and auto-scroll.

Needs this: agentuity/sdk#969

Changes

Backend

Area Files What
SQLite Reader src/lib/sqlite/ (4 files) OpenCodeDBReader adapted from SDK — reads OpenCode v1.2.0 schema
Archive Pipeline src/lib/archive.ts Downloads SQLite from sandbox → parses → stores in PostgreSQL
DB Schema src/db/schema.ts + 2 migrations 4 archive tables + indexes + archiveStatus column
Archive API src/routes/session-detail.ts GET /:id/archive, GET /:id/archive/children, GET /:id/archive/children/:childId, GET /:id/children
SSE Proxy src/routes/chat.ts Forwards ALL events tagged with _meta: { sessionId, isParent }
Delete Flow src/routes/session-detail.ts Archives before destroying sandbox, soft-deletes session

Frontend

Area Files What
Archive View ArchivedBanner.tsx, ChatPage.tsx Read-only archived session view with stats + Fork button
Sub-Agent UI ChildSessionView.tsx, ToolCallCard.tsx Expandable nested conversation inside tool call cards
Hooks useChildSessions.ts, useSessionEvents.ts Child session fetching/caching + live child event reducer
Types AppContext.tsx Added archiveStatus to Session type

Review Fixes Applied

  • ✅ N+1 queries → batch inArray() queries
  • ✅ Archive race condition → optimistic locking (WHERE archiveStatus='none')
  • ✅ Missing FK indexes → migration 0007 adds 5 indexes
  • ✅ Live child reading → graceful degradation (returns empty + warning)
  • ✅ Archive status validation → specific error codes (503/410/400)
  • ✅ Frontend cache → clears on archived mode change

Testing

  • bunx tsc --noEmit ✅ zero errors
  • Needs manual testing for:
    • Archive flow: delete a session → verify archived view loads
    • Sub-agent inspection: run multi-agent task → expand tool call → verify child conversation
    • Live streaming: run multi-agent task → expand while running → verify live events
    • Fork from archive: click Fork button → verify new session starts
    • Migration: run drizzle-kit push or drizzle-kit migrate to apply schema changes

…reaming

Add SQLite-backed session archiving so terminated sandboxes retain
conversation history, plus a sub-agent transparency UI that lets users
inspect and live-stream child agent sessions nested in the parent chat.

Session Archive:
- Adapt OpenCodeDBReader from SDK to read OpenCode v1.2.0 SQLite schema
- Add 4 PostgreSQL archive tables with indexes (Drizzle migrations)
- Archive pipeline downloads SQLite from sandbox before destruction
- Soft-delete sessions to preserve archive access
- GET /api/sessions/:id/archive serves archived data in frontend format
- ArchivedBanner component with stats and Fork button
- ChatPage detects archived state, loads read-only view

Sub-Agent Inspection:
- 3 new API endpoints for archived + live child session data
- useChildSessions hook with caching (archived + live modes)
- ChildSessionView expandable panel for nested conversations
- ToolCallCard detects task/agentuity_background_task tools
- 'Inspect Agent Session' button shows child agent's full conversation

Live Sub-Agent Streaming:
- SSE proxy forwards all events tagged with _meta session metadata
- useSessionEvents reducer handles child events (messages, parts, status)
- ChildSessionView renders live streaming with animated Live indicator
- Auto-scroll during active streaming

Review fixes applied:
- Batch inArray() queries replacing N+1 pattern
- Optimistic locking for archive race prevention
- Foreign key indexes on all archive tables
- Graceful degradation for live child session reading
- Specific error codes for archive status (503/410/400)
- Frontend cache invalidation on archived mode change
@coderabbitai
Copy link

coderabbitai bot commented Feb 14, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands and usage tips.

- Add IF NOT EXISTS guards to all CREATE TABLE, ADD COLUMN, ADD
  CONSTRAINT, and CREATE INDEX statements across migrations 0002-0007
- Matches pattern established in 0000_init.sql for safe re-runs
- Downgrade live child session errors to debug level since sandbox
  OpenCode SQLite DB is not yet available in production
…ggers

Replace one-shot archive-on-delete with event-driven background syncing.
Uses sandboxExecute to query OpenCode's SQLite DB inside the sandbox
(no file download), parses JSON output, and does full-replace in
PostgreSQL archive tables.

- Add syncSessionArchive() using sandboxExecute + JSON + PG upsert
- Hook into SSE session.idle events for debounced sync (5 min)
- Add cron route fallback at /api/cron/archive-sync (every 5 min)
- Remove archive attempt from delete endpoint (proactive sync handles it)
- Add best-effort sync on termination detection
- Add lastArchivedAt column to chatSessions + migration 0008
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant